import prompt from '@system.prompt';
import router from '@system.router';
export default {
    onInit(){
        this.recent = this.$app.$def.searhData.recent
//        prompt.showToast({
//            message:this.recent
//        })
        console.log(this.recent);
    },
    data: {
//        recent:[
//            { id:1,word:"11.11" },
//            { id:2,word:"穿搭" },
//            { id:3,word:"11大促" },
//            { id:4,word:"球鞋" },
//            { id:5,word:"棉服" }
//        ],
            recent:[],

        hot:[
            { id:1,word:"11.11" },
            { id:2,word:"穿搭" },
            { id:3,word:"板鞋" },
            { id:4,word:"球鞋" },
            { id:5,word:"板鞋" },
            { id:6,word:"大衣" },
        ],
        keyword: { id:'',word:'' }
    },
    back(){
        router.back();

    },
//    获取输入框的值
    change(e){

        this.keyword.word = e.text

        prompt.showToast({
            message: this.keyword.word
        })
    },
//    添加最近搜索
    addchange(e){
        this.keyword.word = e
        this.keyword.id =this.recent.length+1
        this.recent.push(this.keyword)
        this.$app.$def.searhData.recent=this.recent

        prompt.showToast({
            message:e
        })
        console.log('aaa')
    },
//
    labelsearch(e){
        this.keyword.word = e
        router.push({
            uri:"pages/searchresult/searchresult",
            params:{
                searchword:this.keyword.word
            }
        })
        prompt.showToast({
            message:e
        })
    },
    hotsearch(e){
        this.keyword.word = e
        this.keyword.id =this.$app.$def.searhData.recent.length+1
        this.$app.$def.searhData.recent.push(this.keyword)
        router.push({
            uri:"pages/searchresult/searchresult",
            params:{
                searchword:this.keyword.word
            }
        })
        this. keyword= { id:'',word:'' }
//        this.$app.$def.searhData.recent=this.recent

    },

    goresult(){
        this.addchange(this.keyword.word)
        router.push({
            uri:"pages/searchresult/searchresult",
            params:{
                searchword:this.keyword.word
            }
        })
        this. keyword= { id:'',word:'' }

    },
    deleterecent(){
        this.recent=[]
        this.$app.$def.searhData.recent=this.recent
    }
}
